#include <cstdio>
#include <queue>
using namespace std;
int n;
struct node {
	int id, p, time;
	bool operator< (const node &x)const {
		if (this->time + this->p == x.time + x.p) {
			return this->id > x.id;
		}
		return this->time + this->p > x.time + x.p;
	}
};
priority_queue <node> q;
int main() {
	int a, b;
	char c;	
	while (scanf("Register%c", &c)) {
		scanf ("%d %d", &a, &b);
		scanf ("\n");
		q.push ((node){a, b, 0});	
	}
	scanf ("#");
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		node u = q.top();
		q.pop();
		printf ("%d\n", u.id);
		q.push((node){u.id, u.p, u.time + u.p});
	}
	return 0;
}	